import { util } from '../../../../utils/util';
var app = getApp();
//思想品德中的其他页面
Page({
  mixins: [],
  data: {
     activityType:'',    //活动类型
     instanceType:'',       //实例类型
     honorFiles:[], //图片数组
     //选择获奖类型
     honorType:'',
     gradeArr:[
        {css:'',id:'1',value:'国家级'},{css:'',id:'2',value:'省级'},{css:'',id:'3',value:'市级'},{css:'',id:'4',value:'县级'},{css:'',id:'5',value:'校级'}
    ]
    },
    on_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.gradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.honorType=arr[index].id;
      me.setData( me.data);
    },

    onSubmit(e) {
      var me = this;
      var obj = e.detail.value;
      var dataObj=obj;
      dataObj['honorType'] =me.data.honorType;
      //做非空校验
      if(util.validation(dataObj)){
          obj['honorType'] = parseInt(me.data.honorType);
          obj['files'] = me.data.honorFiles;
          obj['activityType'] = parseInt(me.data.activityType);
          obj['instanceType'] = parseInt(me.data.instanceType);
          obj['showName'] = 'otherName';

          var data = {
              activityType: parseInt(me.data.activityType),
              instanceType: parseInt(me.data.instanceType),
              itemInfo : obj,
          }
         //提交数据
          util.submitRecord(data);
      } 
    },
 
  
  onLoad(query) {
    // 页面加载
    console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
    var arr = query.honorFiles.split(",");
    this.setData({
      activityType: query.activityType,
      instanceType: query.instanceType,
      honorFiles: arr,
      honorType:'',
     gradeArr:[
        {css:'',id:'1',value:'国家级'},{css:'',id:'2',value:'省级'},{css:'',id:'3',value:'市级'},{css:'',id:'4',value:'县级'},{css:'',id:'5',value:'校级'}
     ]
    });
  },
  onUnload() {
    // 页面被关闭
    wx.setStorageSync("honorFiles", []);
  },
});
